package com.ydlclass;

import com.ydlclass.api.Hello;
import com.ydlclass.bootstrap.ClientBootstrap;
import com.ydlclass.compress.gzip.GzipCompress;
import com.ydlclass.core.URL;
import com.ydlclass.factory.proxy.YrpcClientProxy;
import com.ydlclass.loadbalance.loadbalancer.ConsistentHashLoadBalancer;
import com.ydlclass.registry.zk.ZookeeperRegistry;
import com.ydlclass.serialization.jdk.JdkSerializer;
import lombok.extern.slf4j.Slf4j;

/**
 * @author it楠老师
 * @createTime 2023-03-09
 */
@Slf4j
public class Client {
    public static void main(String[] args) {

        // 1、创建一个客户端的接口代理，用于生成客户端代理
        YrpcClientProxy<Hello> yrpcClientProxy = new YrpcClientProxy<>(Hello.class);

        // 2、获取客户端实例，并进行配置
        URL url = new URL("zookeeper://127.0.0.1:2181");
        ClientBootstrap.getInstance()
                .registry(new ZookeeperRegistry(url))
                .loadBalance(new ConsistentHashLoadBalancer())
                .compress(new GzipCompress())
                .serialization(new JdkSerializer())
                .clientProxy(yrpcClientProxy);

        // 3、获取代理对象，并调用其方法
        for (int i = 0; i < 50; i++) {
            Hello hello = yrpcClientProxy.get();
            String server = hello.hello("client-->" + i);
            log.info("server --> {}" ,server);
        }


    }

}
